
f_in = open('input.txt', 'r')
f_out = open('output.txt', 'w')

N = int(f_in.readline().rstrip())

for i in range(1,N+1):
    m={}
    for c in  f_in.readline().rstrip():
        if(c in "HACKERUP"):
            m[c] = m[c] + 1 if (c in m) else 1

    r = 0
    while(1):
        done = False
        for c in "HACKERCUP":
            if(c in m and m[c]>0):
                m[c] -= 1 
            else:
                done = True 
                break
        if(done):
            break
        r += 1
    
    f_out.write('Case #{0}: {1}{2}'.format(i, r, '\n' if (i!=N) else ''))
    
f_in.close()
f_out.close()